//这里才是真正存放请求函数的地方
import http from "./http.js";
import api from "./api.js";
import axios from "axios";
//请求城市的信息
export function getCity() {
  return axios({
    method: "GET",
    url: api.city,
  });
}
//添加地址
export function addAddress(data) {
  return http({
    method: "POST",
    url: api.address,
    data,
  });
}
//获取地址
export function getAddress() {
  return http({
    method: "GET",
    url: api.address,
  });
}
//修改地址
export function editAddress(id, data) {
  return http({
    method: "PUT",
    url: `${api.address}/${id}`,
    data,
  });
}
//删除地址
export function delAddress(id) {
  return http({
    method: "DELETE",
    url: `${api.address}/${id}`,
  });
}
//获取轮播图
export function getLunbo(data) {
  return axios({
    method: "GET",
    url: api.lunbo,
    params: data,
  });
}
//获取分类信息

export function getClassify(data) {
  return axios({
    method: "GET",
    url: api.classify,
    params: data,
  });
}
//获取商品列表
export function getGoods(data) {
  return axios({
    method: "GET",
    url: api.goods,
    params: data,
  });
}
//登陆
export function userLogin(data) {
  return axios({
    method: "POST",
    url: api.login,
    //请求的体的参数应该放到data中
    data,
  });
}
//获取单个商品的详细信息
export function getGoodDetail(id) {
  return axios({
    method: "GET",
    url: `${api.goods}/${id}`,
  });
}
//添加购物车
export function addCart(data) {
  //因为要带token，所以用http
  return http({
    method: "POST",
    url: api.cart,
    data,
  });
}
//获取购物车列表
export function getCart(params) {
  //因为要带token，所以用http
  return http({
    method: "GET",
    url: api.cart,
    params,
  });
}
//更新购物车
export function updateCart(id, data) {
  return http({
    //axios文档PUT请求的使用方式和POST类似
    method: "PUT",
    url: api.cart + "/" + id,
    data,
  });
}
//删除购物车
export function delCart(id) {
  return http({
    method: "DELETE",
    url: api.cart + "/" + id,
  });
}
